import java.util.*;

public class LightTransistor {
    static int count;
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        String[] arr = new String[] {"a", "b", "c", "d", "e", "f", "g"};
        Map<String, String[]> map = new HashMap<>();
        map.put("a", new String[] {"b", "f"});
        map.put("b", new String[] {"a", "g", "c"});
        map.put("c", new String[] {"g", "b", "d"});
        map.put("d", new String[] {"e", "c"});
        map.put("e", new String[] {"f", "g", "d"});
        map.put("f", new String[] {"e", "g", "a"});
        map.put("g", new String[] {"f", "b", "e", "c"});
        arrangement(map, arr, new LinkedList<>(), 0);
        System.out.println(count);
        scan.close();
    }

    public static void arrangement(Map<String, String[]> map, String[] arr, List<String> list, int index) {
        if (!list.isEmpty() && isLinked(list, map, list.size())) {
            count ++;
        }
        if (index >= 7) {
            return;
        }
        for (int i = index; i < 7; i++) {
                list.add(arr[i]);
                arrangement(map, arr, list, i + 1);
                // 回溯
                list.remove(list.size() - 1);
            }
    }

    public static boolean isLinked(List<String> list, Map<String, String[]> map, int len) {
        List<String> comp = new LinkedList<>();
        Collections.addAll(comp, map.get(list.get(0)));
        List<String> remain = new LinkedList<>();
        for (int i = 1; i < list.size(); i++) {
            if (!comp.contains(list.get(i))) {
                remain.add(list.get(i));
            } else {
                Collections.addAll(comp, map.get(list.get(i)));
            }
        }
        while (!remain.isEmpty()) {
            List<String> remain1 = new LinkedList<>();
            for (int i = remain.size() - 1; i >= 0; i--) {
                if (!comp.contains(remain.get(i))) {
                    remain1.add(remain.get(i));
                } else {
                    Collections.addAll(comp, map.get(remain.get(i)));
                }
            }
            if (remain.size() == remain1.size()) {
                return false;
            }
            remain = remain1;
        }
        return true;
    }

}
